/*
 *  Copyright 2008-2010 www.jrails.org
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.rails.extjs.panel;

import java.util.ArrayList;
import java.util.List;

import org.rails.extjs.Option;
import org.rails.extjs.javascript.JavaScript;

public class ToolTip extends Tip {

	public ToolTip(String target) {
		super();
		setTarget(target);
	}

	public ToolTip(Option configOptions) {
		super(configOptions);
	}

	public ToolTip(String target,String title) {
		super(title);
		setTarget(target);
	}

	public ToolTip(String target,String id, String title) {
		super(id, title);
		setTarget(target);
	}
	
	public void setAutoHide(Boolean autoHide){
		addOption("autoHide", autoHide);
	}
	
	public Boolean isAutoHide(){
		return getBoolean("autoHide",true);
	}
	
	public void setAnchorOffset(Integer anchorOffset){
		addOption("anchorOffset", anchorOffset);
	}
	
	public Integer getAnchorOffset(){
		return getInteger("anchorOffset",0);
	}
	
	public void setAnchorToTarget(Boolean anchorToTarget){
		addOption("anchorToTarget",anchorToTarget);
	}
	
	public Boolean isAnchorToTarget(){
		return getBoolean("anchorToTarget",true);
	}
	
	public void setDelegate(String delegate){
		addOption("delegate", delegate);
	}
	
	public String getDelegate(){
		return getString("delegate","");
	}
	
	public void setDismissDelay(Integer dismissDelay){
		addOption("dismissDelay", dismissDelay);
	}
	
	public Integer getDismissDelay(){
		return getInteger("dismissDelay",5000);
	}
	
	public void setHideDelay(Integer hideDelay){
		addOption("hideDelay", hideDelay);
	}
	
	public Integer getHideDelay(){
		return getInteger("hideDelay",200);
	}
	
	public void setMouseOffset(Number x,Number y){
		List<JavaScript> mouseOffset = new ArrayList<JavaScript>();
		mouseOffset.add(new JavaScript(x.toString()));
		mouseOffset.add(new JavaScript(y.toString()));
		addOption("mouseOffset",mouseOffset);
	}
	
	@SuppressWarnings("unchecked")
	public List<JavaScript> getMouseOffset(){
		return (List<JavaScript>)getOption("mouseOffset");
	}
	
	public void setShowDelay(Integer showDelay){
		addOption("showDelay", showDelay);
	}
	
	public Integer getShowDelay(){
		return getInteger("showDelay",500);
	}
	
	public void setTarget(String target){
		addOption("target", target);
	}
	
	public String getTarget(){
		return getString("target","");
	}
	
	public void setTrackMouse(Boolean trackMouse){
		addOption("trackMouse", trackMouse);
	}
	
	public Boolean isTrackMouse(){
		return getBoolean("trackMouse",false);
	}	
	
	@Override
	public String getScript() {
		script = new StringBuffer("");
		createItems();
		script.append("new Ext.ToolTip(");
		script.append(createOptions());
		script.append(");");
		return script.toString();
	}

}
